<?php

namespace App\Http\Controllers\Api\V2;

use App\Models\XoAnchors;
use App\Models\XoAnchorVideo;
use Illuminate\Http\Request;
use App\Models\Authorization;
use App\Transformers\NewsTransformer;
use Illuminate\Support\Facades\DB;
use Log;

class XoAnchorVideoController extends BaseController
{
    /**
     *
     * 获取主播视频列表
     * @param {Object} Request
     */
    public function index(Request $request)
    {
		$type = $request->get('videoType', -1);
		
        //当前页数 默认1
		$page = $request->get('page', 1);
		//每页的条数
		$perPage = $request->get('perPage', 1);
		//计算每页分页的初始位置
		$offset = ($page * $perPage) - $perPage;
		if($type == -1){
			$rows = XoAnchorVideo::orderBy('id', 'desc')->paginate($perPage);
		}else{
			$rows = XoAnchorVideo::where('video_type', $type)->orderBy('id', 'desc')->paginate($perPage);
		}

		//获取主播信息
		$anchorIds = field_vals($rows, 'anchorId');
		$anchorRows = XoAnchors::where('id'. 'in', $anchorIds)->select();
		$ahchorKvs = kv_rows($anchorRows, 'id');
		
		 //实例化LengthAwarePaginator类，并传入对应的参数
		$dataArray = $rows->toArray();
		$retArr = [];
		foreach($dataArray['data'] as $index => $one){
			
		$ahchorKvs = kv_rows($anchorRows, 'id');
			if(isset($ahchorKvs[$one['anchorId']]) && $ahchorKvs[$one['anchorId']]){
				$one['anchor_name'] = $ahchorKvs[$one['anchorId']]['name'];
			}
		}
		
		return $this->returnSuccess($dataArray);
    }
    
    /**
     *
     * 获取通知消息id的详细内容
     * @param {Object} Request
     */
    public function detail(Request $request)
    {
        $id = $request->get('id');
		$detail = XoAnchors::where('id', $id)->first();
    	
    	return $this->returnSuccess($detail);
    }
	
	
	
}
